<?php

class distribution extends spModel
{
	public $pk = "id"; // 数据表的主键
    public $table = "distributions"; // 数据表的名称

	function create($row) {
		$mDistribute = spClass('distribute_task');
		$ret = $mDistribute->find(array('mbid'=>$row['originid']));

		$mUser = spClass('user');
		$mUser->runSql("UPDATE user SET cash = cash+".$ret['bonus']." WHERE uid = ".$row['uid']);

		$mUserLog = spClass('userlog');
		$distributeBlogUrl = 'http://api.t.sina.com.cn/'.$row['uid'].'/statuses/'.$row['mbid'];
		$logArray	  = array(
							'uid' => $row['uid'],
							'type'=> 'distribute',
							'content' => 'Get '.$ret['bonus'].' for distribute blog '.$distributeBlogUrl,
							'dateline'=> time()
						);
		$lastLogId    = $mUserLog->create($logArray);

		$cashLogArray	  = array(
							'uid' => $row['uid'],
							'logid' => $lastLogId,
							'amount'=> +$ret['bonus'],
							'dateline'=> time()
						);
		$mUserCashLog = spClass('usercashlog');
		$mUserCashLog->create($cashLogArray);

		parent::create($row);
	}

}